import 'package:get/get.dart';
import 'package:flutter/material.dart';
import '../utils/resability.dart';

class HomeController extends GetxController {
  var categorizationData =
      <Map>[
        {'name': '科幻', 'url': 'assets/images/fenlei/kehuan.png'},
        {'name': '历史', 'url': 'assets/images/fenlei/lishi.png'},
        {'name': '言情', 'url': 'assets/images/fenlei/yanqing.png'},
        {'name': '田园', 'url': 'assets/images/fenlei/tianyuan.png'},
        {'name': '武侠', 'url': 'assets/images/fenlei/wuxia.png'},
        {'name': '现实', 'url': 'assets/images/fenlei/xianshi.png'},
        {'name': '玄幻', 'url': 'assets/images/fenlei/xuanhuan.png'},
        {'name': '校园', 'url': 'assets/images/fenlei/xiaoyuan.png'},
      ].obs;
  var createrData =
      <Map>[
        {'name': '匪我思存', 'url': 'assets/images/zuozhe/zuojia1.png'},
        {'name': '顾漫', 'url': 'assets/images/zuozhe/zuojia2.png'},
        {'name': '丁墨', 'url': 'assets/images/zuozhe/zuojia3.png'},
        {'name': '天蚕土豆', 'url': 'assets/images/zuozhe/zuojia4.png'},
        {'name': '辰东', 'url': 'assets/images/zuozhe/zuojia5.png'},
        {'name': '我吃西红柿', 'url': 'assets/images/zuozhe/zuojia6.png'},
      ].obs;
  var bookdata =
      <Map>[
        {
          'name': '微微一笑',
          'url': 'assets/images/fengmian/1.png',
          'creater': '匪我思存',
        },
        {
          'name': '一世之尊',
          'url': 'assets/images/fengmian/2.png',
          'creater': '丁墨',
        },
        {'name': '星辰变', 'url': 'assets/images/fengmian/3.png', 'creater': '顾漫'},
        {
          'name': '武动乾坤',
          'url': 'assets/images/fengmian/4.png',
          'creater': '天蚕土豆',
        },
        {'name': '东宫', 'url': 'assets/images/fengmian/5.png', 'creater': '辰东'},
        {
          'name': '千山暮雪',
          'url': 'assets/images/fengmian/6.png',
          'creater': '我吃西红柿',
        },
      ].obs;

  List<Widget> getList(list) {
    List<Widget> result = [SizedBox(width: 30)];
    for (var i in list) {
      result.add(
        Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
              width: 100,
              height: 100,
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(10),
                image: DecorationImage(
                  image: AssetImage(i['url']),
                  fit: BoxFit.cover,
                ),
              ),
            ),
            SizedBox(height: 8),
            Text(
              i['name'],
              style: TextStyle(color: Colors.white, fontSize: 15),
            ),
          ],
        ),
      );
      result.add(SizedBox(width: 15));
    }
    result.last = SizedBox(width: 30);
    return result;
  }

  Widget getBookList(list) {
    List<Widget> result = [];

    for (var i in list) {
      result.add(
        Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            ClipRRect(
              borderRadius: BorderRadius.circular(10),
              child: Image.asset(i['url'], width: 100),
            ),
            SizedBox(height: 10),
            SizedBox(
              width: 100,
              child: Text(
                i['name'],
                style: TextStyle(color: Colors.white, fontSize: 15),
                overflow: TextOverflow.ellipsis,
              ),
            ),
            SizedBox(
              width: 100,
              child: Text(
                i['creater'],
                style: TextStyle(color: text_color, fontSize: 13),
                overflow: TextOverflow.ellipsis,
              ),
            ),
          ],
        ),
      );
    }

    var row1 = Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: result.sublist(0, 3),
    );
    var row2 = Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: result.sublist(3, 6),
    );

    return Column(
      children: [row1, SizedBox(height: 40), row2, SizedBox(height: 20)],
    );
  }
}
